package models

import "gorm.io/gorm"

type User struct {
	ID    uint `gorm:"primaryKey"`
	Name  string
	Email string
}

// Repository 层，提供公共方法
type UserRepository struct {
	DB *gorm.DB
}

func (r *UserRepository) GetAll() ([]User, error) {
	var users []User
	if err := r.DB.Find(&users).Error; err != nil {
		return nil, err
	}
	return users, nil
}

func (r *UserRepository) GetById(id uint) (*User, error) {
	var user User
	if err := r.DB.First(&user, id).Error; err != nil {
		return nil, err
	}
	return &user, nil
}
